/*
 * Copyright (C), 2017, 上海云首信息科技有限公司
 *
 * Author: 邓哲航
 * Date: 2018/5/17 上午1:21
 * History:
 * <author>    <time>    <version>    <desc>
 *
 */
package com.leaptocloud.easycloud.demo.exceptionmapper;

import org.apache.shiro.authz.UnauthenticatedException;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

/**
 * @author 邓哲航
 * @see
 * @since 2.3.8
 */
public class AuthExceptionMapper implements ExceptionMapper<Exception> {

    @Override
    public Response toResponse(Exception e) {
        Response.ResponseBuilder ResponseBuilder;

        if (e instanceof UnauthenticatedException) {
            ResponseBuilder = Response.status(Response.Status.UNAUTHORIZED).header("msg",e.getMessage());
        } else {
            ResponseBuilder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
        }
        e.printStackTrace();

        return ResponseBuilder.build();
    }
}
